package com.me.libgdx_test;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.scenes.scene2d.ui.Window.WindowStyle;
import com.badlogic.gdx.scenes.scene2d.utils.Align;

//This class adds a dialog box to the stage that is passed into the function
public class ClassDialogBox {
	private Stage stage;
	private String title,message;
	private Dialog dialog;
	private Skin skin;
	ClassDialogBox(Stage stage, String title, String message, Skin skin, boolean continue_button){
		this.title = title;
		this.message = message;
		this.stage = stage;
		this.skin = skin;
		construct_dialog(continue_button);
	}
	public void construct_dialog(boolean continue_button){
		
		Label label = new Label(message, skin);
		label.setFontScale(1.4f);
		//label.setWidth(Gdx.graphics.getWidth()/8);
		label.setAlignment(Align.center);
		label.setWrap(true);
		
		//ClassLabelFormat format = new ClassLabelFormat(label);
		
		dialog = new Dialog(title, skin) {
			    protected void result (Object object) {
			            System.out.println("Chosen: " + object);
			    }
			};

		//WindowStyle style = skin.get(WindowStyle.class);	
		//float window_style_width = 4 * style.background.getMinWidth();
		
		dialog.padTop(75).padBottom(50);
		dialog.getContentTable().add(label).width(Gdx.graphics.getWidth()/2).padTop(30).padLeft((15*Gdx.graphics.getWidth())/100).padRight((15*Gdx.graphics.getWidth())/100).row();
		dialog.getButtonTable().padTop(50);
		
		if(continue_button){
			TextButton dbutton = new TextButton("Done", skin);
			//dbutton.setWidth(dbutton.getWidth()*2);
			//dbutton.setSize(dbutton.getWidth()*2, dbutton.getHeight()*2);
			dialog.button(dbutton, true);
			//dialog.getButtonTable().setWidth(dialog.getButtonTable().getWidth()*2);
			//dialog.getButtonTable().setHeight(dialog.getButtonTable().getHeight()*2);
			//dbutton.setSize(dbutton.getWidth()*2, dbutton.getHeight()*2);
		}
			
		dialog.key(Keys.ENTER, true).key(Keys.ESCAPE, false);
		dialog.invalidateHierarchy();
		dialog.invalidate();
		dialog.layout();
		dialog.show(stage);
	}
	public Dialog get_dialog(){
		return dialog;
	}
	class ClassLabelFormat{
		public float width, height, left, bottom;
		ClassLabelFormat(Label label){
			width = label.getWidth();
			height = label.getHeight();
			left = label.getOriginX();
			bottom = label.getOriginY();
		}
	}
}
